package com.example;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class MyGenerator {
    public static void main(String[] args) {
        //创建mp代码生成器对象
        AutoGenerator ag = new AutoGenerator();

//        ag.setGlobalConfig() 全局配置
//        ag.setPackageInfo()  包配置
//        ag.setStrategy()  策略配置
//        ag.setDataSource()  配置数据库连接池
        String path = System.getProperty("user.dir");
        GlobalConfig gc = new GlobalConfig();
        gc.setOutputDir(path+"/src/main/java");
        gc.setBaseColumnList(true);
        gc.setBaseResultMap(true);
        gc.setAuthor("yunan");
        gc.setMapperName("%sMapper");
        gc.setServiceName("I%sService");
        gc.setServiceImplName("%sServiceImpl");
        gc.setControllerName("%sController");
        gc.setIdType(IdType.AUTO);
        gc.setActiveRecord(true);
        ag.setGlobalConfig(gc);

        PackageConfig pc = new PackageConfig();
        pc.setParent("com.example");
        ag.setPackageInfo(pc);

        DataSourceConfig dc = new DataSourceConfig();
        dc.setDriverName("com.mysql.jdbc.Driver");
        dc.setUrl("jdbc:mysql://localhost:3306/artical43");
        dc.setUsername("root");
        dc.setPassword("root");
        ag.setDataSource(dc);

        StrategyConfig sc = new StrategyConfig();
        sc.setNaming(NamingStrategy.underline_to_camel);
        sc.setColumnNaming(NamingStrategy.underline_to_camel);
        ag.setStrategy(sc);

        //生成代码
        ag.execute();

    }
}
